<template>
  <div class="skill-tag-form">
    <h3 class="section-title">技能特长</h3>
    
    <div class="skill-input-section">
      <el-row :gutter="20">
        <el-col :span="16">
          <el-input
            v-model="newSkill"
            placeholder="请输入技能名称，按回车键添加"
            @keyup.enter="addSkill"
            clearable
          />
        </el-col>
        <el-col :span="8">
          <el-button type="primary" @click="addSkill" :disabled="!newSkill">
            <el-icon><Plus /></el-icon>
            添加技能
          </el-button>
        </el-col>
      </el-row>
    </div>
    
    <div v-if="skillList.length === 0" class="empty-state">
      <el-empty description="暂无技能特长，请添加" />
    </div>
    
    <div v-else class="skill-tags">
      <el-tag
        v-for="(skill, index) in skillList"
        :key="index"
        closable
        type="info"
        @close="removeSkill(index)"
        class="skill-tag"
      >
        {{ skill }}
      </el-tag>
    </div>
    
    <div class="skill-suggestions">
      <p class="suggestion-title">常用技能推荐：</p>
      <div class="suggestion-tags">
        <el-tag
          v-for="suggestion in skillSuggestions"
          :key="suggestion"
          @click="addSkillFromSuggestion(suggestion)"
          class="suggestion-tag"
          :disabled="skillList.includes(suggestion)"
        >
          {{ suggestion }}
        </el-tag>
      </div>
    </div>
  </div>
</template>

<script>
import { Plus } from '@element-plus/icons-vue'

export default {
  name: 'SkillTagInput',
  components: { Plus },
  props: {
    modelValue: {
      type: Array,
      default: () => []
    }
  },
  emits: ['update:modelValue'],
  data() {
    return {
      skillList: [...this.modelValue],
      newSkill: '',
      skillSuggestions: [
        'JavaScript', 'Python', 'Java', 'C++', 'C#', 'PHP', 'Ruby', 'Go', 'Rust',
        'React', 'Vue', 'Angular', 'Node.js', 'Express', 'Django', 'Spring Boot',
        'MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Elasticsearch',
        'Docker', 'Kubernetes', 'AWS', 'Azure', 'Google Cloud',
        'Git', 'Linux', 'Docker', 'Jenkins', 'CI/CD',
        'Machine Learning', 'Data Analysis', 'Statistics', 'Excel',
        'Photoshop', 'Illustrator', 'Figma', 'Sketch',
        'Project Management', 'Agile', 'Scrum', 'Leadership',
        'Communication', 'Teamwork', 'Problem Solving', 'Creativity'
      ]
    }
  },
  watch: {
    modelValue: {
      handler(newVal) {
        this.skillList = [...newVal]
      },
      deep: true
    },
    skillList: {
      handler(newVal) {
        this.$emit('update:modelValue', newVal)
      },
      deep: true
    }
  },
  methods: {
    addSkill() {
      if (!this.newSkill.trim()) {
        return
      }
      
      const skill = this.newSkill.trim()
      
      // 检查是否已存在
      if (this.skillList.includes(skill)) {
        this.$message.warning('该技能已存在')
        return
      }
      
      this.skillList.push(skill)
      this.newSkill = ''
    },
    removeSkill(index) {
      this.skillList.splice(index, 1)
    },
    addSkillFromSuggestion(skill) {
      if (!this.skillList.includes(skill)) {
        this.skillList.push(skill)
      }
    }
  }
}
</script>

<style scoped>
.skill-tag-form {
  margin-bottom: 24px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid #409eff;
}

.skill-input-section {
  margin-bottom: 16px;
}

.empty-state {
  margin: 20px 0;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.skill-tag {
  margin-right: 8px;
  margin-bottom: 8px;
  font-size: 14px;
}

.skill-suggestions {
  border-top: 1px solid #e4e7ed;
  padding-top: 16px;
}

.suggestion-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 12px;
  font-weight: 500;
}

.suggestion-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.suggestion-tag {
  font-size: 12px;
  cursor: pointer;
  transition: all 0.3s;
}

.suggestion-tag:hover:not(:disabled) {
  background-color: #409eff;
  color: white;
}

.suggestion-tag:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
</style> 